package com.coco.controller;

import com.coco.model.NaviInfo;
import com.coco.model.NaviInfoCondition;
import com.coco.model.RootModel;
import com.coco.service.RootService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GHOSTLaycoo
 * @date 2020/4/12 0012 - 下午 14:41
 */
@RestController
@RequestMapping("/root")
@Slf4j
public class RootController {

    @Autowired
    private RootService rootService;

    @ApiOperation(value = "保存权限信息")
    @PostMapping("/save")
    public ResponseEntity<Integer> save(@RequestBody RootModel rootModel){
        int result =  rootService.save(rootModel);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiOperation(value = "删除权限信息")
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Integer> delete(@PathVariable("id") String id){
        int result =  rootService.delete(id);
        return ResponseEntity.ok(result);
    }

    @ApiModelProperty(value = "修改权限信息")
    @PostMapping("/update")
    public ResponseEntity<Integer> update(@RequestBody RootModel rootModel){
        int result =  rootService.update(rootModel);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiModelProperty(value = "查询权限信息")
    @GetMapping("/getRootByCondition")
    public ResponseEntity<List<RootModel>> getRootByCondition(@RequestParam(value = "keyWord",required = false) String keyWord){
        List<RootModel> result =  rootService.getRootByCondition(keyWord);
        return ResponseEntity.ok(result);
    }

}
